package com.atguigu.gmall.cart.service.impl;

import com.atguigu.gmall.cart.mapper.CartInfoMapper;
import com.atguigu.gmall.cart.service.CartAsyncService;
import com.atguigu.gmall.model.cart.CartInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author mqx
 * @date 2021-2-26 14:07:31
 */
@Service
public class CartAsyncServiceImpl implements CartAsyncService {

    @Autowired
    private CartInfoMapper cartInfoMapper;

    //  添加一个注解变为异步操作
    @Override
    @Async
    public void updateCartInfo(CartInfo cartInfo) {
        //  更新数据方法
        QueryWrapper<CartInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",cartInfo.getUserId());
        queryWrapper.eq("sku_id",cartInfo.getSkuId());
        cartInfoMapper.update(cartInfo,queryWrapper); // 跟条件包含主键，也包含其他条件的更新

        //  cartInfoMapper.updateById(cartInfo); // 根据主键更新
    }

    @Override
    @Async
    public void saveCartInfo(CartInfo cartInfo) {
        // 保存方法
        cartInfoMapper.insert(cartInfo);
    }
}
